<template>
	<view class="waterfall-item-container">
		<view class="waterfall-item" @tap="onTap">
			<view class="image">
				<image class="image" :src="params.coverImg" :style="{ height: `${h}px` }" mode="aspectFill"
					@load="emitHeight" @error="emitHeight">
				</image>
				<text class="text" v-show="params.type == 1">美食</text>
				<text class="text" v-show="params.type == 2">酒店</text>
				<text class="text" v-show="params.type == 3">景点</text>
				<text class="text" v-show="params.type == 4">攻略</text>
			</view>
			<view class="content">
				<view class="content-title">{{params.name}}</view>
			</view>
			<view class="price" v-show="params.type == 3">
				<view class="content-title" v-if="params.price!=='0'">
					<text class="one">￥{{params.price}}</text>
					<text class="two">起</text>
				</view>
				<view class="content-title" v-if="params.price=='0'">
					<text class="two">免费</text>
				</view>
			</view>
			<view class="price" v-show="params.type == 2">
				<view class="content-title" v-if="params.price!==null">
					<text class="one">￥{{params.price}}</text>
					<text class="two">起</text>
				</view>
				<view class="content-title" v-if="params.price==null">
					<text class="two">满房</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "helangWaterfallItem",
		options: {
			virtualHost: true
		},
		props: {
			params: {
				type: Object,
				default () {
					return {}
				}
			},
			tag: {
				type: String | Number,
				default: ''
			},
			index: {
				type: Number,
				default: -1
			}
		},
		data() {
			return {
				likenumShow: true,
				h: 0,
				FormData: [{
					arriveDate: '', //	到达时间(yyyy-MM-dd)
					leaveDate: '', //离开时间(yyyy-MM-dd)
					limit: 10, //每页显示记录数
					page: 1, //当前页码
					name: '',
					islandId: ''
				}],
			};
		},
		mounted() {
			this.h = this.params.height
			this.FormData[0].arriveDate = this.getDays(0);
			this.FormData[0].leaveDate = this.getDays(1);
			// this.getDays(0)
			// this.getDays(1)
		},

		methods: {
			getDays(day) {
				var today = new Date();
				var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;
				today.setTime(targetday_milliseconds); //注意，这行是关键代码
				var tYear = today.getFullYear();
				var tMonth = today.getMonth();
				var tDate = today.getDate();
				var week = today.getDay();
				tMonth = this.doHandleMonth(tMonth + 1);
				tDate = this.doHandleMonth(tDate);
				if (day == 0) {
					this.FormData[0].arriveDate = tYear + '-' + tMonth + '-' + tDate
				} else if (day == 1) {
					this.FormData[0].leaveDate = tYear + '-' + tMonth + '-' + tDate
				}
				return tYear + "-" + tMonth + "-" + tDate

			},
			doHandleMonth(month) {
				var m = month;
				if (month.toString().length == 1) {
					m = "0" + month;
				}
				return m;
			},
			// 点赞
			like(obj) {
				let list = {
					id: obj.id,
					type: obj.publisherType
				}

				this.$api.get('/api/introdution/Like', list)
					.then(res => {
						// this.getList(this.id)
						this.$showToast(res.data.data)
						if (res.data.data == '点赞成功') {
							this.likenumShow = false

						} else if (res.data.data == '取消成功') {
							this.likenumShow = true
						}
					})
			},

			// 发出组件高度信息，在此处可以区分正确和错误的加载，给予错误的提示图片
			emitHeight(e) {
				const query = uni.createSelectorQuery().in(this);
				query.select('.waterfall-item-container').boundingClientRect(data => {
					let height = Math.floor(data.height);

					this.$emit("height", height, this.$props.tag);

				}).exec();
			},
			// 去详情
			onTap() {
				// 去美食详情
				if (this.$props.params.type == 1) {
					uni.navigateTo({
						url: "/pagesTrip/fineFood/details/details?list=" + JSON.stringify({
							...this.$props.params
						})
					})
				} // 去酒店详情
				else if (this.$props.params.type == 2) {
					uni.navigateTo({
						url: "/pagesTrip/hotel/details/index?list=" +
							JSON.stringify([{
								homestayId: this.$props.params.id,
								name: this.$props.params.name,
								...this.FormData[0],
							}]),
					});
				} //去景点详情
				else if (this.$props.params.type == 3) {
					uni.removeStorageSync('spid_old');
					uni.removeStorageSync('price_old');
					uni.navigateTo({
						url: "/pagesTrip/scenicSpots/spotDetail?spid=" + this.$props.params.id + '&price=' +
							this.$props.params.price
					})
				} // 去攻略详情
				else if (this.$props.params.type == 4) {
					uni.navigateTo({
						url: '/pages/index/waterfall/details?id=' + this.$props.params.id
					})

				}

			}
		}
	}
</script>

<style lang="scss" scoped>
	.waterfall-item {
		// padding: 4rpx;
		box-sizing: border-box;
		// margin: 2rpx;
		background-color: #fff;
		border-radius: 16rpx;
		font-size: 28rpx;
		color: #666;
		overflow: auto;
		margin: 6rpx 4rpx;
		// box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
		box-shadow: 0px 4px 16px 0px rgba(0, 0, 0, 0.08);
		// box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2);

		.image {
			border-radius: 16rpx 16rpx 0 0;
			display: block;
			width: 100%;
			position: relative;

			// 默认设置一个图片的大约值
			// height: 100%;
			.text {
				position: absolute;
				top: 0;
				left: 0;
				font-size: 22rpx;
				color: #ffffff;
				// background: #ff7d01;
				// background-color: argb(0, 0, 0, 0.5);
				// background: argb(0, 0, 0, 0.5);
				background: rgba(0, 0, 0, 0.5);

				border-radius: 16rpx 0 18rpx 0;
				padding: 4rpx 6rpx;
			}
		}

		.content {
			padding: 16rpx;
			// margin-top: 16rpx;

			.content-title {
				display: -webkit-box;
				-webkit-line-clamp: 2;
				/* 指定最大行数 */
				-webkit-box-orient: vertical;
				/* 垂直排列文本 */
				overflow: hidden;
				font-size: 28rpx !important;
				color: #333 !important;
			}

			.content-user {
				display: flex;
				justify-content: space-between;
				margin: 8rpx;

				.content-user-list {
					display: flex;
					align-items: center;

					.images {
						border-radius: 30rpx;
						width: 40rpx;
						height: 40rpx;
					}

					.content-user-name {
						width: 190rpx;
						// margin: 0 10rpx;
						font-size: 24rpx;
						color: #777777;
					}
				}

				.content-user-praise {
					display: flex;
					align-items: center;

					.images {
						// border-radius: 15px;
						width: 30rpx;
						height: 30rpx;
					}
				}
			}

		}

		.price {
			padding: 16rpx;
			// margin-top: 16rpx;

			.content-title {

				.one {
					font-size: 36rpx !important;
					color: #FF4141 !important;
					font-weight: Bold;
				}

				.two {
					font-size: 24rpx !important;
					color: #ABB0B5 !important;
					// font-weight: Bold;
				}

			}
		}
	}
</style>